/*
 * DatagramBuilder Library: serialize/deserialize data to/from datagram
 * Copyright (C) 2008 Rakov Ilya <RakovIlya@gmail.com>
 *
 * This library can be distributed under the terms of the GNU LGPLv2.
 * See the file COPYING.LIB.
 */


#ifndef DATAGRAM_LISTPARSERIMPL_H_
#define DATAGRAM_LISTPARSERIMPL_H_


/**
 * @file ListParserImpl.h
 *
 * @brief ListParser implementation file
 *
 * @date Dec 12, 2008
 * @author Rakov Ilya
 */


template< class ElemT, class CountT >
ListParser< ElemT, CountT >::
ListParser( Parser &parser )
  : parser_ ( parser ),
    treated_( 0 )
{
  parser_ >> count_;
}


template< class ElemT, class CountT >
CountT ListParser< ElemT, CountT >::
GetCount() const
{
  return count_.Get();
}


template< class ElemT, class CountT >
bool ListParser< ElemT, CountT >::
IsTreated() const
{
  return ( GetCount() == treated_ );
}


template< class ElemT, class CountT >
ListParser< ElemT, CountT >&
ListParser< ElemT, CountT >::operator >>( ElemT &value )
{
  parser_ >> value;
  ++treated_;

  return *this;
}


template< class ElemT, class CountT >
ListParser< ElemT, CountT >&
ListParser< ElemT, CountT >::operator >>( const ElemT &value )
{
  parser_ >> value;
  ++treated_;

  return *this;
}


template< class ElemT, class CountT >
ListParser< Tag<ElemT>, CountT >::
ListParser( Parser &parser )
  : listParser_( parser )
{
  Parser::ScopedTransaction transaction( parser );

  SerializeImpl< ElemT >::DeSerializeTag( parser );
}


template< class ElemT, class CountT >
CountT ListParser< Tag<ElemT>, CountT >::
GetCount() const
{
  return listParser_.GetCount();
}


template< class ElemT, class CountT >
bool ListParser< Tag<ElemT>, CountT >::
IsTreated() const
{
  return listParser_.IsTreated();
}


template< class ElemT, class CountT >
ListParser< Tag<ElemT>, CountT >&
ListParser< Tag<ElemT>, CountT >::operator >>( ElemT &value )
{
  listParser_ >> value;

  return *this;
}


template< class ElemT, class CountT >
ListParser< Tag<ElemT>, CountT >&
ListParser< Tag<ElemT>, CountT >::operator >>( const ElemT &value )
{
  listParser_ >> value;

  return *this;
}


#endif /* DATAGRAM_LISTPARSERIMPL_H_ */
